<template>
    <div>
<h1>登录</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>账号</td>
                    <td>
                        <input type="text" v-model="data.name">
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="data.mima">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-success" @click="getsage">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores/success';
const success=useUserStore();
const router=useRouter();
const data=ref({
  "id": 1,
  "name": "张三",
  "mima": "123"
})
const getsage=()=>{
    axios.get("https://localhost:7263/api/xues/denglu",{params:data.value}).then(res=>{
         if(res.data.id==-1){
            alert('不存在用户名');
            return
        }
        if(res.data.id==-2){
            alert('密码错误');
            return
        }
        if(res.data.id>0){
            alert('登录成功');
              success.data.name=data.value.name
            router.push({path: '/'})
        }
    })
}

</script>

<style scoped>

</style>